﻿using System;

namespace HeroldIT.Dnn.JQuery
{
    /// <summary>
    /// An <see cref="Attribute"/> for marking fields or properties as settings for
    /// json serialization.
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public class SettingAttribute : Attribute
    {
        #region properties

        /// <summary>
        /// Gets or sets an alternate name for the setting.
        /// </summary>
        public string SettingName { get; set; }

        /// <summary>
        /// Gets or sets options for serializing Dictionary properties.
        /// </summary>
        public DictionarySerializationMode DictionarySerializationMode { get; set; }

        /// <summary>
        /// Gets or sets options for serializing empty values.
        /// </summary>
        public EmptyValueSerializationMode EmptyValueSerializationMode { get; set; }

        /// <summary>
        /// Gets or sets options for string values.
        /// </summary>
        public StringValueOptions StringValueOptions { get; set; }

        /// <summary>
        /// Gets or sets options for serializing DateTime values.
        /// </summary>
        public DateTimeSerializationMode DateTimeSerializationMode { get; set; }

        #endregion

        #region constructors

        /// <summary>
        /// Creates a new <see cref="SettingAttribute"/>.
        /// </summary>
        public SettingAttribute()
        {
            this.DictionarySerializationMode = DictionarySerializationMode.Normal;
            this.EmptyValueSerializationMode = EmptyValueSerializationMode.Omit;
            this.StringValueOptions = StringValueOptions.Normal;
            this.DateTimeSerializationMode = DateTimeSerializationMode.DateTime;
        }

        /// <summary>
        /// Creates a new <see cref="SettingAttribute"/> with the given alternate name.
        /// </summary>
        public SettingAttribute(string settingName)
            : this()
        {
            this.SettingName = settingName;
        }

        #endregion
    }
}
